package com.atguigu.day15.stringbudder;

import org.junit.Test;

public class StringBuilderTest {
    @Test
    public void test01() {
        StringBuilder sbf = new StringBuilder();
    }

    @Test
    public void test02() {
        StringBuilder sbf = new StringBuilder("ABCD");
        System.out.println("sbf.length() = " + sbf.length());
        sbf.setLength(2);
        System.out.println("sbf = " + sbf);
    }

    @Test
    public void test03() {
        StringBuilder sbf = new StringBuilder("杨幂");
        System.out.println("sbf = " + sbf);
        //追加
        sbf.append("赵丽颖");
        System.out.println("sbf = " + sbf);//杨幂赵丽颖
        sbf.append(3.14);
        sbf.append(666);
        System.out.println("sbf = " + sbf);//杨幂赵丽颖3.14666
        //在指定位置插入
        sbf.insert(1, "妲己");
        System.out.println("sbf = " + sbf);//杨妲己幂赵丽颖3.14666
        //删除指定下标的数据
        sbf.deleteCharAt(6);
        System.out.println("sbf = " + sbf);
        //删除范围数据[开始,结束)
        sbf.delete(0, 5);
        System.out.println("sbf = " + sbf);//丽3.14666
        //修改指定下标的值
        sbf.setCharAt(3, '你');
        System.out.println("sbf = " + sbf);//丽3.你4666

        int indexedOf = sbf.indexOf("你");
        System.out.println("indexedOf = " + indexedOf);//3

    }

    @Test
    public void test04() {
        StringBuilder sbf = new StringBuilder("ABCD");
        sbf.replace(0, 2, "赵丽颖");
        System.out.println("sbf = " + sbf);//赵丽颖CD

        sbf.reverse();

        System.out.println("sbf = " + sbf);//DC颖丽赵

        //将StringBuilder --> String
        String s = sbf.toString();
        System.out.println("s = " + s);


    }
}
